open Base

type 'a t = Source.set * (Source.State.t -> 'a)

let empty : Source.set = Set.empty (module Source)

let return x = empty, (fun _ -> x)
let const = return
let map (s, g) ~f = s, fun t -> f (g t)
let map2 (s1, g1) (s2, g2) ~f = Set.union s1 s2, fun t -> f (g1 t) (g2 t)
let both bx by = map2 bx by ~f:(fun x y -> (x, y))
let ( >>| ) b f = map ~f b

let of_source s = Source.singleton s, Source.State.get_exn s
let time = of_source Source.time

let dependencies (s, _) = Set.to_sequence s
let sample (_, f) = f
